<?php
//判断是否是搜索爬虫
function isSpider() {
    $agent= strtolower($_SERVER['HTTP_USER_AGENT']);
    if (!empty($agent)) {
        $spiderSite= array(
                "TencentTraveler",
                "Baiduspider+",
                "BaiduGame",
                "Googlebot",
                "msnbot",
                "Sosospider+",
                "Sogou web spider",
                "ia_archiver",
                "Yahoo! Slurp",
                "YoudaoBot",
                "Yahoo Slurp",
                "MSNBot",
                "Java (Often spam bot)",
                "BaiDuSpider",
                "Voila",
                "Yandex bot",
                "BSpider",
                "twiceler",
                "Sogou Spider",
                "Speedy Spider",
                "Google AdSense",
                "Heritrix",
                "Python-urllib",
                "Alexa (IA Archiver)",
                "Ask",
                "Exabot",
                "Custo",
                "OutfoxBot/YodaoBot",
                "yacy",
                "SurveyBot",
                "legs",
                "lwp-trivial",
                "Nutch",
                "StackRambler",
                "The web archive (IA Archiver)",
                "Perl tool",
                "MJ12bot",
                "Netcraft",
                "MSIECrawler",
                "WGet tools",
                "larbin",
                "Fish search",
        );
        foreach($spiderSite as $val) {
            $str = strtolower($val);
            if (strpos($agent, $str) !== false) {
                return true;
            }
        }
    } else {
        return false;
    }
}

//前台时间展示
function time2str($timestamp) {
    if(!$timestamp) return '';
    $diff = NOW_TIME - $timestamp;
    if($diff > 0){
        $day_diff = floor($diff / 86400);
        //如果是当天发布
        if($day_diff == 0){
            if($diff < 60) return L('now');
            if($diff < 3600) return floor($diff / 60).'m';
            if($diff < 7200) return '1h';
            if($diff < 86400) return floor($diff / 3600).'h';
        }
        if($day_diff == 1) return '1d';
        if($day_diff < 7) return $day_diff.'d';
        if($day_diff < 31) return ceil($day_diff / 7) . 'w';
        return '';
    }else{
        return L('now');
    }
}